/**
 *
 */
package com.ssyt.examinationsystem.service.impl;

import com.ssyt.examinationsystem.dao.IChoiceInfoDAO;
import com.ssyt.examinationsystem.dao.impl.ChoiceInfoDAOImpl;
import com.ssyt.examinationsystem.entity.ChoiceInfo;
import com.ssyt.examinationsystem.entity.PageBean;
import com.ssyt.examinationsystem.service.IChoiceInfoService;

import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 */
public class ChoiceInfoServiceImpl implements IChoiceInfoService {
    private IChoiceInfoDAO choiceDao = new ChoiceInfoDAOImpl();

    /*
     * 添加选择题的业务实现类
     *
     * @see
     * com.ssyt.examinationsystem.service.IChoiceInfoService#addChoiceInfo(com.
     * ssyt.examinationsystem.entity.ChoiceInfo)
     */
    @Override
    public int addChoiceInfo(ChoiceInfo choice) {
        return choiceDao.addChoiceInfo(choice);
    }

    @Override
    public List<Map<String, Object>> getSingles() {
        return choiceDao.getSingles();
    }

    @Override
    public List<Map<String, Object>> getMultiple() {
        return choiceDao.getMultiple();
    }

    /*
     * (non-Javadoc)
     *
     * @see com.ssyt.examinationsystem.service.IChoiceInfoService#getChoice()
     */
    @Override
    public List<Map<String, Object>> getChoice() {
        return choiceDao.getChoice();
    }

    @Override
    public int updateChoice(ChoiceInfo choice) {
        return choiceDao.updateChoice(choice);
    }

    @Override
    public int deleteChoice(String choiceId) {
        return choiceDao.deleteChoice(choiceId);
    }

    @Override
    public PageBean getChoiceByPage(PageBean page) {
        // 获取分页总记录数
        Integer totalRecords = choiceDao.getTotalCount();
        // 获取每页显示数
        Integer pageSize = page.getPageSize();
        // 获取当前页
        Integer currentPage = page.getCurrentPage();
        List<Map<String, Object>> choiceList = choiceDao.getChoiceByPage(page);
        // 创建一个分页对象
        PageBean pageBean = new PageBean(totalRecords, pageSize, currentPage);
        pageBean.setList(choiceList);

        return pageBean;
    }

}
